package org.xx.sipahi;

import java.util.Objects;

import static org.apache.commons.lang3.StringUtils.trimToEmpty;

/**
 * 栏目。
 */
public final class Category {
    public static final Category EMPTY = new Category(null);

    /**
     * 表示无需任何权限即可访问。
     */
    public static final String ANY_AUTHORITY = "";

    /**
     * 表示任意登录用户均可访问。
     */
    public static final String ANY_AUTHENTICATED_AUTHORITY = "*";

    private final Integer id;
    private final String title;
    private final String description;
    private final int pageSize;
    private final String authority;
    private final int module;
    private final boolean enabled;
    private final String tpl1;
    private final String tpl2;

    public Category(
            Integer id
    ) {
        this(id, "", "", 0, ANY_AUTHORITY, 1, false, "", "");
    }

    public Category(
            Integer id,
            String title,
            String description,
            int pageSize,
            String authority,
            int module,
            boolean enabled,
            String tpl1,
            String tpl2
    ) {
        this.id = id;
        this.title = trimToEmpty(title);
        this.description = trimToEmpty(description);
        this.pageSize = pageSize;
        this.authority = trimToEmpty(authority);
        this.module = module;
        this.enabled = enabled;
        this.tpl1 = trimToEmpty(tpl1);
        this.tpl2 = trimToEmpty(tpl2);
    }

    public Integer getId() {
        return this.id;
    }

    public String getTitle() {
        return this.title;
    }

    public String getDescription() {
        return this.description;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public String getAuthority() {
        return this.authority;
    }

    public int getModule() {
        return this.module;
    }

    public boolean isEnabled() {
        return this.enabled;
    }

    public String getTpl1() {
        return this.tpl1;
    }

    public String getTpl2() {
        return this.tpl2;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(this.getId());
    }

    @Override
    public boolean equals(
            Object obj
    ) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof Category)) {
            return false;
        }
        final var other = (Category) obj;
        return Objects.equals(this.id, other.id);
    }
}
